不用runat="server"如何保存<input type="file">中的文件?
来源:百度知道 编辑:UC知道 时间:2024/05/17 02:01:28
前台代码如下,用于实现预览待上传图片,上传不能设成runat="server",那么如何保存上传文件呢?我试过用{System.Web.HttpFileCollection file = HttpContext.Current.Request.Files;HttpPostedFile fileupload=file;}来寻找上传文件但是提示错误:无法将类型“System.Web.HttpPostedFile”隐式转换为“System.Web.HttpFileCollection”,请高手赐教!
<input type="file" name="file" id="file5" onchange="preview()" />
<asp:Label ID="Label2" runat="server" Width="57px"></asp:Label>
<img id="pic" src="" alt="暂无缩略图" height="90" width="120" />
<script type="text/javascript">
function preview()
{var x = document.getElementById("file");
if(!x || !x.value) return;
var patn = /\.jpg$|\.jpeg$|\.gif$|\.bmp$/i;
if(patn.test(x.value))
{
var y = document.getElementById("pic");
<input type="file" name="file" id="file5" onchange="preview()" />
<asp:Label ID="Label2" runat="server" Width="57px"></asp:Label>
<img id="pic" src="" alt="暂无缩略图" height="90" width="120" />
<script type="text/javascript">
function preview()
{var x = document.getElementById("file");
if(!x || !x.value) return;
var patn = /\.jpg$|\.jpeg$|\.gif$|\.bmp$/i;
if(patn.test(x.value))
{
var y = document.getElementById("pic");
第一个问题:
我觉得你是没有理解集合和元素之间的关系!
HttpFileCollection 就像是个巧克力盒子,HttpPostedFile就是巧克力,盒子里有好多巧克力,但是能说巧克力盒子就是巧克力么?!?!?!
你要是想从盒子中获取巧克力,那你就要先知道,盒子里有多少块巧克力,你想要拿第几块巧克力!
而你的做法就像是拿起了一个巧克力盒子...连盖子都不打开直接用牙咬盒子去了.....................
具体到代码层面来说就是这样写:
System.Web.HttpFileCollection file = HttpContext.Current.Request.Files;
HttpPostedFile fileupload=file[编号];
第二个问题:
你不把input放进FROM里面如何提交呢?
但是话说回来...如果你放上去一个input编译之后网页中会多出来一个FORM...冲突就是这么来的..
你还不如这样呢..
把那些烂七八遭的服务器端控件干掉...
想要验证输入自己写脚本验证.
lable就直接<LABLE>或者<DIV>得了~~
然后呢..这个网页不是ASPX了..直接HTML!
然后用一个FORM包起来...
提交到另一个ASPX或ASHX
那边处理服务器端用
Request.Files[第几个]去取.
不用runat="server"如何保存<input type="file">中的文件?
<script language="vbscript" runat="server">的编译错误
<Script language="VBScript" runat="server">
<script runat="server"> asp.net (vb)数据库连接
服务器端表单<form runat="server" />的action属性有没有用吗?
<asp:Repeater ID="myrepeater3" runat="server">中ID是怎么定义的">
<asp:HyperLink ID="nextbtn" Runat="server">下一页</asp:HyperLink>
<uc1:head id="Head1" runat="server"></uc1:head>是什么意思,如何修改里面的数据?
否定句第三人称不用加"S"吗?
Txtbox怎样放在runat=server窗体控件中